<?php
namespace app\admin\logic;

use app\common\logic\BaseLogic;
use app\common\model\Menu;
use app\common\validate\AdminVal;

Class MenuLogic extends BaseLogic{
    public function create($data)
    {
        (new Menu())->save($data);
        return true;
    }



    public function listing($keyword,$page=10)
    {

        $where = [];
        !empty($keyword) && $where['title'] = ['like',"%$keyword%"];

        $r = Menu::where($where)->paginate($page)->toArray();
        return $r;
    }


    public function update($data,$methods = 'post')
    {
        if ($methods === 'get'){
            $r = Menu::get($data);
        }else{
            $data['update_time'] = time();
            $r = (new Menu())->save($data,['id'=>$data['id']]);
        }
        return $r;
    }


    public function delete($ids)
    {
        $str = trim($ids,',');
        $_arr = explode(',',$str);
        $where[] = ['id','in',$_arr];
        $r = Menu::where($where)->delete();
        return $r;
    }


    public function createlm($data)
    {

        $data['targe'] = '_self';
        $data['sort'] = 0;
        $data['status'] = 1;
        $data['icon'] = 'fa fa-tachometer';
        $data['create_time'] = time();
        $data['update_time'] = time();
        (new Menu())->save($data);
        return true;
    }
}